import {
  Component,
  OnInit,
  Input,
  Output,
  EventEmitter,
} from '@angular/core';


// 弹窗位置
type position = 'top' | 'bottom' | 'center';
type PopupSwitch = (state: boolean) => void;

@Component({
  selector: 'app-popup',
  templateUrl: './popup.component.html',
  styleUrls: [ './popup.component.less' ]
})
export class PopupComponent implements OnInit {
  private _hidden = true;
  @Input()
  set hidden(value) {
    this._hidden = value;
  }
  @Input() position: position = 'bottom';
  @Output() getPopupSwitch: EventEmitter<PopupSwitch> = new EventEmitter();
  constructor() { }

  ngOnInit() {
    const fn = this.popupSwitch.bind(this);
    this.getPopupSwitch.emit(fn);
  }

  // 切换开关
  popupSwitch (state: boolean) {
      this._hidden = state === undefined ? !this._hidden : !!state;
  }

}
